package com.cy.web.action.scenic;

import java.util.LinkedHashMap;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cy.bean.Paging;
import com.cy.bean.scenic.Scenic;
import com.cy.service.scenic.ScenicService;
import com.cy.web.action.BaseAction;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class ForeScenicAction extends BaseAction {

	@Resource
	private ScenicService scenicService;

	/**
	 * 新闻列表
	 * @return
	 */
	public String list() {
		scenicList();
		return "list";
	}

	/**
	 * 景点列表
	 */
	private void scenicList() {
		Paging<Scenic> paging = new Paging<Scenic>();
		// 用于存放排序的条件
		LinkedHashMap<String, String> orderby = new LinkedHashMap<>();
		// 按照id降序排列
		orderby.put("id", "asc");
		// 查询条件where，查询允许显示的新闻
		String where = "o.scenic_visible=?1";
		Object[] params = {true};
		// 将查询的结果放到分页类中
		paging.setQueryResult(scenicService.getScrollData(-1,-1, where, params, orderby));
		// 将分页对象存放到request域对象中
		ActionContext.getContext().put("paging", paging);
	}
	
	/**
	 * 查看一条景点
	 * @return
	 */
	public String detail() {
		// 景点列表
		scenicList();
		// 要查看的景点
		Scenic scenic = scenicService.find(getId());
		ActionContext.getContext().put("scenic", scenic);
		// 上一篇 
		ActionContext.getContext().put("prev", scenicService.prev(getId()));
		//下一篇
		ActionContext.getContext().put("next", scenicService.next(getId()));
		return "detail";
	}
}
